library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.2 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.2 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)
#read our cleaned up data into the env
data_analytic <- readRDS("../../../data/interim/analytic2023_c1.rds")
#Injury deaths Raw(v135):Number of deaths due to injury per 100,000 population.
ggplot(data_analytic, aes(y = v005_rawvalue, x = v135_rawvalue))+
geom_point(color="green", alpha =0.5)+
geom_smooth()+
xlab(paste("Number of deaths due to injury per 100,000 population")) +
ylab("Preventable Hospital Stays")+
theme(panel.background = element_rect(fill = "black"),
plot.background = element_rect(fill = "black"),
panel.grid.major = element_line(color = "white", size = 0.1),
panel.grid.minor = element_line(color = "white", size = 0.05),
text = element_text(color = "white"))
## Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
## ℹ Please use the `linewidth` argument instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 131 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 131 rows containing missing values (`geom_point()`).

v135_xaxis_vars <- c("v135_race_hispanic", "v135_race_white", "v135_race_asian", "v135_race_aian", "v135_race_black")
#Race: Hispanic
for(var in v135_xaxis_vars){
va135byracegraph <-ggplot(data_analytic, aes_string(y = "v005_rawvalue", x = var))+
geom_point(color="green", alpha =0.5)+
geom_smooth()+
xlab(paste(var, ":Number of deaths due to injury per 100,000 population.")) +
ylab("Preventable Hospital Stays")+
theme(panel.background = element_rect(fill = "black"),
plot.background = element_rect(fill = "black"),
panel.grid.major = element_line(color = "white", size = 0.1),
panel.grid.minor = element_line(color = "white", size = 0.05),
text = element_text(color = "white"))
print(va135byracegraph)
}
## Warning: `aes_string()` was deprecated in ggplot2 3.0.0.
## ℹ Please use tidy evaluation idioms with `aes()`.
## ℹ See also `vignette("ggplot2-in-packages")` for more information.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2266 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2266 rows containing missing values (`geom_point()`).

## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 187 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 187 rows containing missing values (`geom_point()`).

## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2847 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2847 rows containing missing values (`geom_point()`).

## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2870 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2870 rows containing missing values (`geom_point()`).

## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 1993 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 1993 rows containing missing values (`geom_point()`).

#Suicide raw(v161):Number of deaths due to suicide per 100,000 population (age-adjusted).
ggplot(data_analytic, aes(y = v005_rawvalue, x = v161_rawvalue))+
geom_point(color="green", alpha =0.5)+
geom_smooth()+
xlab(paste("Number of deaths due to suicide per 100,000 population (age-adjusted)")) +
ylab("Preventable Hospital Stays")+
theme(panel.background = element_rect(fill = "black"),
plot.background = element_rect(fill = "black"),
panel.grid.major = element_line(color = "white", size = 0.1),
panel.grid.minor = element_line(color = "white", size = 0.05),
text = element_text(color = "white"))
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 715 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 715 rows containing missing values (`geom_point()`).

v161_xaxis_vars <- c("v161_race_hispanic", "v161_race_white", "v161_race_asian", "v161_race_aian", "v161_race_black")
#Race: Hispanic
for(var in v161_xaxis_vars){
va161byracegraph <-ggplot(data_analytic, aes_string(y = "v005_rawvalue", x = var))+
geom_point(color="green", alpha =0.5)+
geom_smooth()+
xlab(paste(var, "Number of deaths due to suicide per 100,000 population (age-adjusted).")) +
ylab("Preventable Hospital Stays")+
theme(panel.background = element_rect(fill = "black"),
plot.background = element_rect(fill = "black"),
panel.grid.major = element_line(color = "white", size = 0.1),
panel.grid.minor = element_line(color = "white", size = 0.05),
text = element_text(color = "white"))
print(va161byracegraph)
}
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2828 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2828 rows containing missing values (`geom_point()`).

## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 846 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 846 rows containing missing values (`geom_point()`).

## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 3016 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 3016 rows containing missing values (`geom_point()`).

## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 3096 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 3096 rows containing missing values (`geom_point()`).

## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2852 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2852 rows containing missing values (`geom_point()`).

#fire arm deaths raw(v148):Number of deaths due to firearms per 100,000 population.
ggplot(data_analytic, aes(y = v005_rawvalue, x = v148_rawvalue))+
geom_point(color="green", alpha =0.5)+
geom_smooth()+
xlab(paste("Number of deaths due to firearms per 100,000 population.")) +
ylab("Preventable Hospital Stays")+
theme(panel.background = element_rect(fill = "black"),
plot.background = element_rect(fill = "black"),
panel.grid.major = element_line(color = "white", size = 0.1),
panel.grid.minor = element_line(color = "white", size = 0.05),
text = element_text(color = "white"))
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 875 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 875 rows containing missing values (`geom_point()`).

v148_xaxis_vars <- c("v148_race_hispanic", "v148_race_white", "v148_race_asian", "v148_race_aian", "v148_race_black")
#Race: Hispanic
for(var in v148_xaxis_vars){
va148byracegraph <- ggplot(data_analytic, aes_string(y = "v005_rawvalue", x = var))+
geom_point(color="green", alpha =0.5)+
geom_smooth()+
xlab(paste(var, ":Number of deaths due to firearms per 100,000 population.")) +
ylab("Preventable Hospital Stays")+
theme(panel.background = element_rect(fill = "black"),
plot.background = element_rect(fill = "black"),
panel.grid.major = element_line(color = "white", size = 0.1),
panel.grid.minor = element_line(color = "white", size = 0.05),
text = element_text(color = "white"))
print(va148byracegraph)
}
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2859 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2859 rows containing missing values (`geom_point()`).

## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 1052 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 1052 rows containing missing values (`geom_point()`).

## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 3090 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 3090 rows containing missing values (`geom_point()`).

## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 3115 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 3115 rows containing missing values (`geom_point()`).

## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2576 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2576 rows containing missing values (`geom_point()`).
